/*******************************************************************************
 * Title: PIC Global Definitions
 *
 *  Author: Matthew Spinks
 *
 * File: global_defs.h
 *
 * Created on March 14, 2014, 6:54 PM
 *
 * Description:
 *  This global_defs file is to hold any sort of simple, definition or macro
 *  that is meant to be shared with every file. I've worked with as many as
 *  three micrcontrollers at a time and I can never remember which way the
 *  IO's work. It can be different depending if you're using Microchip,
 *  Atmel, or Freescale. Also, I've added the crytstal frequency, so that you
 *  can use built-in delay statements like __delay_ms()
 *
*******************************************************************************/

#ifndef GLOBAL_DEFS_H
    #define	GLOBAL_DEFS_H

// Oscillator frequency
#define _XTAL_FREQ  8000000     // Necessary for using delay functions
/****************************************************************/
/* Built-in delay routine					*/
/****************************************************************/
#pragma intrinsic(_delay)
extern void _delay(unsigned long);
#pragma intrinsic(_delaywdt)
extern void _delaywdt(unsigned long);
#pragma intrinsic(_delay3)
extern void _delay3(unsigned char);
// NOTE: To use the macros below, YOU must have previously defined _XTAL_FREQ
#define __delay_ns(x) _delay((unsigned long)((x)*(_XTAL_FREQ/4000000000.0)))
#define __delay_us(x) _delay((unsigned long)((x)*(_XTAL_FREQ/4000000.0)))
#define __delay_ms(x) _delay((unsigned long)((x)*(_XTAL_FREQ/4000.0)))
#define __delaywdt_us(x) _delaywdt((unsigned long)((x)*(_XTAL_FREQ/4000000.0)))
#define __delaywdt_ms(x) _delaywdt((unsigned long)((x)*(_XTAL_FREQ/4000.0)))

#define INPUT       1
#define OUTPUT      0
#define ANALOG      1
#define DIGITAL     0

// error codes
#define NO_ERROR    0

#endif	/* GLOBAL_DEFS_H */

